package com.dong.nettyconcurrent.c04_heartbeat;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;
import io.netty.handler.timeout.IdleStateHandler;

public class MyHeartServerHandler  extends ChannelInboundHandlerAdapter {

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        super.userEventTriggered(ctx, evt);
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent idleStateEvent = (IdleStateEvent) evt;
            String eventType = null;
            switch (idleStateEvent.state()) {
                case READER_IDLE:{
                    eventType="读空闲"; break;
                }
              case WRITER_IDLE:{ eventType="写空闲";break;}
              case ALL_IDLE:{eventType="读写空闲";break;}
            }
            System.out.println(ctx.channel().remoteAddress()+" 超时时间  "+eventType);
            ctx.channel().close();
        }
    }
}
